# coding:utf-8
"""
    线程
    threading

    Thread  创建线程    Thread(target,args)


    start   启动线程    start()
    join    阻塞直到线程执行结束  join(timeout=None)
    getName 获取线程的名字 getName()
    setName 设置线程名称   setName(name)
    is_alive 判断线程是否存活 is_alive()
    setDaemon 守护线程 setDaemon(True)


    线程的问题
        * 通过线程执行的函数无法获取返回值
        * 多个线程同时修改文件可能造成数据错乱
"""

import random, time
import threading

lists = ['python','django','tornado','flask','bs5','requests','uvloop']
new_lists = []

def work():
    if len(lists) == 0:
        return
    data = random.choice(lists)
    lists.remove(data)
    new_lists.append('%s_new' % data)


if __name__ == '__main__':
    start = time.time()
    t_list = []
    for i in range(len(lists)):
        t = threading.Thread(target=work)
        t_list.append(t)
        t.start()
    for t in t_list:
        t.join()

    print('old list: ', lists)
    print('new list: ', new_lists)
    print('time is %s ' %(time.time() - start))
